import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    redirect: '/home/index',
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/home',
    component: Layout,
    meta: { title: '工作台', icon: 'el-icon-menu' },
    redirect: '/home/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '工作台' }
      },
    ]
  },
  {
    path: '/custom',
    component: Layout,
    meta: { title: '客户管理', icon: 'el-icon-s-custom' },
    redirect: '/custom/company',
    children: [
      {
        path: 'company',
        component: () => import('@/views/custom/company'),
        meta: { title: '客户公司管理' }
      },
      {
        path: 'companyAdd',
        component: () => import('@/views/custom/companyAdd'),
        meta: { title: '添加公司' },
        hidden: true
      },
      {
        path: 'department',
        component: () => import('@/views/custom/department'),
        meta: { title: '客户部门管理' }
      },
      {
        path: 'user',
        component: () => import('@/views/custom/user'),
        meta: { title: '客户账号管理' }
      },
    ]
  },
  {
    path: '/staff',
    component: Layout,
    meta: { title: '员工管理', icon: 'el-icon-s-shop' },
    redirect: '/staff/account',
    children: [
      {
        path: 'account',
        component: () => import('@/views/staff/account'),
        meta: { title: '员工账号管理' }
      },
      {
        path: 'department',
        component: () => import('@/views/staff/department'),
        meta: { title: '部门管理' }
      },
      {
        path: 'role',
        component: () => import('@/views/staff/role'),
        meta: { title: '角色管理' }
      },
      {
        path: 'certificate',
        component: () => import('@/views/staff/certificate'),
        meta: { title: '资质管理' }
      }
    ]
  },
  {
    path: '/data',
    component: Layout,
    meta: { title: '数据管理', icon: 'el-icon-coin' },
    redirect: '/data/field',
    children: [
      {
        path: 'field',
        component: () => import('@/views/data/field'),
        meta: { title: '字段管理' }
      },
      {
        path: 'enum',
        component: () => import('@/views/data/enum'),
        meta: { title: '枚举类型' }
      },
      {
        path: 'target',
        component: () => import('@/views/data/target'),
        meta: { title: '基础数据' }
      },
      {
        path: 'regionPrice',
        component: () => import('@/views/data/regionPrice'),
        meta: { title: '区片价' }
      },
      {
        path: 'park',
        component: () => import('@/views/data/park'),
        meta: { title: '小微园' }
      },
      {
        path: 'community',
        component: () => import('@/views/data/community'),
        meta: { title: '楼盘管理' },
      },
      {
        path: 'enumAdd',
        component: () => import('@/views/data/enumAdd'),
        meta: { title: '枚举添加/编辑' },
        hidden: true
      },
      {
        path: 'targetAdd',
        component: () => import('@/views/data/targetAdd'),
        meta: { title: '基础数据添加/编辑' },
        hidden: true
      },
      {
        path: 'parkAdd',
        component: () => import('@/views/data/parkAdd'),
        meta: { title: '小微园添加/编辑' },
        hidden: true
      },
      {
        path: 'account2',
      },
    ]
  },
  {
    path: '/map',
    component: Layout,
    meta: { title: '地图管理', icon: 'el-icon-map-location' },
    redirect: '/map/look',
    children: [
      {
        path: 'look',
        component: () => import('@/views/map/look'),
        meta: { title: '查看地图' },
      },
      {
        path: 'account2',
      },
    ]
  },
  {
    path: '/inquiry',
    component: Layout,
    meta: { title: '询价管理', icon: 'el-icon-document' },
    redirect: '/inquiry/list',
    children: [
      {
        path: 'person',
        component: () => import('@/views/inquiry/person'),
        meta: { title: '人工询价' },
      },
      {
        path: 'auto',
        component: () => import('@/views/inquiry/auto'),
        meta: { title: '自动询价' },
      },
      {
        path: 'add',
        component: () => import('@/views/inquiry/add'),
        meta: { title: '添加自动询价' },
        hidden: true
      },
      {
        path: 'account2',
      },
    ]
  },
  {
    path: '/report',
    component: Layout,
    meta: { title: '报告管理', icon: 'el-icon-document' },
    redirect: '/report/list',
    children: [
      {
        path: 'list',
        component: () => import('@/views/report/list'),
        meta: { title: '正式报告' },
      },
      {
        path: 'survey',
        component: () => import('@/views/report/survey'),
        meta: { title: '查勘任务' },
      },
      {
        path: 'account2',
      },
    ]
  },
  {
      path: '/crawler',
      component: Layout,
      meta: { title: '爬虫管理', icon: 'el-icon-link' },
      redirect: '/crawler/tb',
      children: [
          {
            path: 'tb',
            component: () => import('@/views/crawler/tb'),
            meta: { title: '阿里法拍' },
          },
          {
            path: 'zr',
            component: () => import('@/views/crawler/zr'),
            meta: { title: '浙江自然数据' },
          }
      ]
  },
  {
    path: '/sys',
    component: Layout,
    meta: { title: '系统管理', icon: 'el-icon-s-tools' },
    redirect: '/sys/pattern',
    children: [
      // {
      //   path: 'pattern/1',
      //   component: () => import('@/views/sys/pattern'),
      //   meta: { title: '机构类型' },
      //   params: '?type=1'
      // },
      // {
      //   path: 'pattern/2',
      //   component: () => import('@/views/sys/pattern'),
      //   meta: { title: '证书类型' },
      //   params: '?type=2'
      // },
      
      {
        path: 'template',
        component: () => import('@/views/sys/template'),
        meta: { title: '案例模板' },
      },
      {
        path: 'inquiryTemplate',
        component: () => import('@/views/sys/inquiryTemplate'),
        meta: { title: '询价模板' },
      },
      {
        path: 'reportTemplate',
        component: () => import('@/views/sys/reportTemplate'),
        meta: { title: '报告模板' },
      },
      {
        path: 'geo',
        component: () => import('@/views/sys/geoBlock'),
        meta: { title: '行政区组团' },
      },

      {
        path: 'enum',
        component: () => import('@/views/sys/enum'),
        meta: { title: '系统枚举' },
      },
      {
        path: 'enumAdd',
        component: () => import('@/views/sys/enumAdd'),
        meta: { title: '枚举添加/编辑' },
        hidden: true
      },
      
      // {
      //   path: 'params',
      //   component: () => import('@/views/sys/params'),
      //   meta: { title: '参数管理' }
      // },
      {
        path: 'account2',
      },
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

export const asyncRoutes = []

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router